/**
 * Class: DGrid3
 *
 * Purpose: 
 *
 * Created: Jan 23, 2010 @ 11:06:19 PM
 * @author Ken Scott
 */
package org.openfantasia.util.math;

import org.openfantasia.util.Copyable;

public class DGrid3 implements Copyable<DGrid3> {

	private static final int N = 2;

	public double p[][][][];


	public DGrid3() {
		p = new double[N][N][N][N];
	}


	public DGrid3(double[][][][] p) {
		if (p[0][0][0].length != N) {
			throw new IllegalArgumentException("Input array must be of length " + N + ", not " + p[0][0][0].length);
		}
		for (int i = 0; i < p.length; i++) {
			this.p[i] = Math3D.copy(p[i]);
		}
	}


	public DGrid3(DGrid3 p) {
		this(p.p);
	}


	public DGrid3 copy() {
		return new DGrid3(p);
	}

	public void copy(DGrid3 that) {
		p = Math4D.copy(that.p);
	}


	public DGrid3 clear() {
		Math4D.fill(p, 0);
		return this;
	}


	public double[][][][] getValue() {
		return p;
	}


	public DGrid3 mulNoise(double frac) {
		p = Math4D.mulNoise(p, frac);
		return this;
	}


	public DGrid3 addNoise(double frac) {
		p = Math4D.addNoise(p, frac);
		return this;
	}


	public DGrid3 neg() {
		p = Math4D.neg(p);
		return this;
	}


	public DGrid3 abs() {
		p = Math4D.abs(p);
		return this;
	}


	public DGrid3 add(DGrid3 a) {
		if(a == null) {
			return this;
		}

		p = Math4D.add(p, a.p);
		return this;
	}


	public DGrid3 sub(DGrid3 a) {
		if(a == null) {
			return this;
		}

		p = Math4D.sub(p, a.p);
		return this;
	}


	public DGrid3 mul(DGrid3 a) {
		if(a == null) {
			return this;
		}

		p = Math4D.mul(p, a.p);
		return this;
	}


	public DGrid3 div(DGrid3 a) {
		if(a == null) {
			return this;
		}

		p = Math4D.div(p, a.p);
		return this;
	}
}